/**
 * 注册
 */
export const SIGNUP = "SIGNUP";
export const SIGNUP_SUCCESS = "SIGNUP_SUCCESS";
export const SIGNUP_FAIL = "SIGNUP_FAIL";
export const RESET_SINGNUP = "RESET_SINGNUP";
export interface SignupPayload {
    email: string,
    name: string, 
    password: string 
}

export interface SignupAction {
   type: typeof SIGNUP,
   payload:SignupPayload
}



export const signup = (payload : SignupPayload): SignupAction => ({
    type: SIGNUP,
    payload,
})

export interface SignupSuccessAction {
    type: typeof SIGNUP_SUCCESS
}


export const SignupSuccess = (): SignupSuccessAction => ({
    type: SIGNUP_SUCCESS
})

export interface SignupFailAction {
    type: typeof SIGNUP_FAIL,
    message: string
}

export const SignupFail = (message: string): SignupFailAction => ({
    type: SIGNUP_FAIL,
    message
})

export interface ResetSignUpAction {
    type: typeof RESET_SINGNUP
}

export const ResetSignUp = (): ResetSignUpAction => ({
    type: RESET_SINGNUP
})



/**
 * 登录
 */

export const SIGNIN = "SIGNIN";
export const SIGNIN_SUCCESS = "SIGNIN_SUCCESS";
export const SIGNIN_FAIL = "SIGNIN_FAIL";

export interface SignInPayload {
    email: string,
    password: string
}

export interface SignInAction {
    type:typeof SIGNIN,
    payload:SignInPayload
}

export const SignIn = (payload : SignInPayload): SignInAction => ({
    type: SIGNIN,
    payload
})

export interface SignInSuccessAction {
    type: typeof SIGNIN_SUCCESS
}

export const SigninSuccess  = (): SignInSuccessAction => ({
    type:SIGNIN_SUCCESS
})

export interface SigninFailAction {
    type : typeof SIGNIN_FAIL,
    message: string
}

export const SigninFail = (message: string ): SigninFailAction => ({
    type : SIGNIN_FAIL,
    message
})

export type AuthUnionType =  SignupAction 
    | SignupFailAction 
    | SignupSuccessAction 
    | ResetSignUpAction
    | SignInAction
    | SignInSuccessAction
    | SigninFailAction
